package y2015.day_15.输入输出流02;

import org.junit.jupiter.api.Test;

import java.io.*;

public class Chai {
    private transient String key;// 不保存

    @Test
    public void main() throws Exception {
        File file = new File("C:\\Documents and Settings\\tarena\\桌面", "apple.png");
        split(file, 1024 * 30);
    }

    private static void split(File file, int size) throws IOException {
        if (file != null && file.exists()) {//如果文件不为空并且文件存在
            File oud = new File("C:\\Documents and Settings\\tarena\\桌面", "sd.png");
            FileInputStream fis = null;//FileInputStream 用于读取诸如图像数据之类的原始字节流。要读取字符流，请考虑使用 FileReader。
            FileOutputStream out = null;
            try {
                fis = new FileInputStream(file);
                byte[] os = new byte[size];
                fis.read(os);
                oud.createNewFile();
                out = new FileOutputStream(oud);
                out.write(os);
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            } finally {
                fis.close();
                out.close();
            }

        }

    }

    private static void merge(File dir, String string) {

    }
}

